<?php
namespace app\admin\validate;

use think\Validate;

class Admin extends Validate
{
    protected $rule = [
        'name'  =>  'require|length:4,10|unique:user,username',
        'email' =>  'email|unique:user,email',
        'password'=>'require|length:4,30|chsDash',
        'repassword'=>'require|confirm:password',
        'cname'  => 'require|checkLenght|unique:auth_cate,cname'
        // 'vercode'=>'checkCode'
    ];

    protected $message  =   [
        'email'        => '邮箱格式错误',
        'username.length'  => '昵称长度为4-10位',
        'password.length'  => '密码长度不能小于4位',
    	'repassword.confirm'  => '两次密码不一致',
        'cname' =>'分类的长度在2-10位'
        // 'vercode.checkCode'  => '人类验证不通过',    
    ];

    protected $scene = [
        // 'login'  =>  ['','password'],
        'set'    =>  ['email','username'],
        'setPassword'=>['password','repassword'],
        'auth_cate'   =>  ['cname']
    ];

    public function checkLenght($value)
    {

        $length = mb_strlen($value,"utf-8");

       if ($length<10&&$length>4) {
           return true;
       }else{
            return false;
       }
    }


    // public function checkCode($value,$rule,$data)
    // {
    // 	if($value==session('answer')){
    // 		return true;
    // 	}else{
    // 		return false;
    // 	}
    // }

}


?>